/*
* ClassroomServiceImpl.java
* Version 1.0.0
* Created on 2019年5月12日
* Copyright kidney
*
*/
package com.java.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.java.entity.Classroom;
import com.java.mapper.ClassroomMapper;
import com.java.mapper.StudentMapper;
import com.java.mapper.TeacherMapper;
import com.java.service.ClassroomService;

/**
 * @author chijinsheng
 * @version 1.0.0
 * @since 
 * 创建时间：2019年5月12日
 * 功能描述：
 */
@Service("ClassroomServiceImpl")
public class ClassroomServiceImpl implements ClassroomService{
	
	
	@Autowired
	private ClassroomMapper cm;
	
	@Autowired
	private StudentMapper sm;
	
	@Autowired
	private TeacherMapper tm;
	

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#selectByUserid(java.lang.Integer)
	 */
	@Override
	public List<Classroom> selectByUserid(Integer userid) {
		// TODO Auto-generated method stub
		return cm.selectByUserid(userid);
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#selectByClassid(java.lang.Integer)
	 */
	@Override
	public List<Classroom> selectByClassid(Integer classId) {
		// TODO Auto-generated method stub
		return cm.selectByClassid(classId);
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#selectAll()
	 */
	@Override
	public List<Classroom> selectAll() {
		// TODO Auto-generated method stub
		return cm.selectAll();
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#insert(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer)
	 */
	@Override
	public Integer insert(Integer userid, Integer classid, String classUse, String weekday, Integer time) {
		// TODO Auto-generated method stub
		Classroom classroom = new Classroom();
		classroom.setClassid(classid);
		classroom.setClassUse(classUse);
		classroom.setTime(time);
		classroom.setWeekday(weekday);
		classroom.setUserid(userid);
		classroom.setPass(false);
		
		System.out.println(classUse);
		System.out.println(classid);
		String username = null;
		if(tm.selectByPrimaryKey(userid)!=null){
			username=tm.selectByPrimaryKey(userid).getUsername();
		}
		else if(sm.selectByPrimaryKey(userid)!=null){
			username=sm.selectByPrimaryKey(userid).getUsername();
		}
		
		classroom.setUsername(username);
		return cm.insert(classroom);
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#delete(java.lang.Integer)
	 */
	@Override
	public Integer delete(Integer id) {
		// TODO Auto-generated method stub
		return cm.deleteByPrimaryKey(id);
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#pass(java.lang.Integer)
	 */
	@Override
	public Integer pass(Integer id) {
		// TODO Auto-generated method stub
		Classroom classroom = new Classroom();
		classroom.setId(id);
		classroom.setPass(true);	
		return cm.updateByPrimaryKeySelective(classroom);
	}

	/* (non-Javadoc)
	 * @see com.java.service.ClassroomService#deleteAll()
	 */
	@Override
	public Integer deleteAll() {
		// TODO Auto-generated method stub
		return cm.deleteAll();
	}

}
